<link rel="import" href="../../../../packages/polymer/polymer.html">
<link rel="import" href="class_ref.html">
<link rel="import" href="instance_ref.html">
<link rel="import" href="library_ref.html">
<link rel="import" href="nav_bar.html">
<link rel="import" href="script_ref.html">
<link rel="import" href="observatory_element.html">
<link rel="import" href="view_footer.html">

<polymer-element name="field-view" extends="observatory-element">
  <template>
    <link rel="stylesheet" href="css/shared.css">
    <nav-bar>
      <top-nav-menu></top-nav-menu>
      <vm-nav-menu vm="{{ field.isolate.vm }}"></vm-nav-menu>
      <isolate-nav-menu isolate="{{ field.isolate }}"></isolate-nav-menu>
      <library-nav-menu library="{{ field.library }}"></library-nav-menu>
      <template if="{{ field.dartOwner is ServiceClass }}">
        <class-nav-menu cls="{{ field.dartOwner }}"></class-nav-menu>
      </template>
      <nav-menu link="{{ makeLink('/inspect', field) }}" anchor="{{ field.name }}" last="{{ true }}"></nav-menu>
      <nav-refresh callback="{{ refresh }}"></nav-refresh>
    </nav-bar>

    <div class="content">
      <h1>
        <template if="{{ field.isStatic }}">static</template>
        <template if="{{ field.isFinal }}">final</template>
        <template if="{{ field.isConst }}">const</template>
        <template if="{{ (field.declaredType.name == 'dynamic' &&
                         !field.isFinal && !field.isConst) }}">
          var
        </template>
        <template if="{{ (field.declaredType.name != 'dynamic') }}">
          {{ field.declaredType.name }}
        </template>
        {{ field.name }}
      </h1>
      <div class="memberList">
        <div class="memberItem">
          <div class="memberName">owner</div>
          <div class="memberValue">
            <any-service-ref ref="{{ field.dartOwner }}"></any-service-ref>
          </div>
        </div>
        <div class="memberItem">
          <div class="memberName">script</div>
          <div class="memberValue">
            <source-link location="{{ field.location }}"></source-link>
          </div>
        </div>
        <template if="{{ !field.isStatic }}">
          <div class="memberItem"
               title="The types observed for this field at runtime.  Fields that are observed to have a single type at runtime or to never be null may allow for additional optimization.">
            <div class="memberName">observed types</div>
            <div class="memberValue">
              <template if="{{ field.guardClass == 'dynamic' }}">
                various
              </template>
              <template if="{{ field.guardClass == 'unknown' }}">
                none
              </template>
              <template if="{{ field.guardClass != 'unknown' &&
                            field.guardClass != 'dynamic' }}">
                <class-ref ref="{{ field.guardClass }}"></class-ref>
                <template if="{{ field.guardNullable }}">
                  &mdash; null observed
                </template>
                <template if="{{ !field.guardNullable }}">
                  &mdash; null not observed
                </template>
              </template>
            </div>
          </div>
        </template>
        <template if="{{ field.staticValue != null }}">
          <div class="memberItem">
            <div class="memberName">static value</div>
            <div class="memberValue">
              <any-service-ref ref="{{ field.staticValue }}"></any-service-ref>
            </div>
          </div>
        </template>
      </div>
    </div>
    <view-footer></view-footer>
  </template>
</polymer-element>

<script type="application/dart" src="field_view.dart"></script>
